public class Main {

}

class Solution {
    int count=0;
    List<List<Integer>> ret=new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        dfs(nums,0,new ArrayList());
        return ret;
    }

    public void dfs(int[] nums,int i ,List<Integer> list){
        if(i==nums.length){
            ret.add(new ArrayList(list));
            return;
        }

        dfs(nums,i+1,list);

        list.add(nums[i]);
        dfs(nums,i+1,list);
        list.remove(list.size()-1);
    }
}

class Solution1{
    List<List<Integer>> ret=new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        List<Integer> list=new ArrayList<>();
        dfs(nums,new boolean[nums.length],list);
        return ret;
    }

    public void dfs(int[] nums,boolean[] vis, List<Integer> list){
        int n=nums.length;
        if(list.size()==n){
            ret.add(new ArrayList(list));
            return;
        }


        for(int i=0;i<n;i++){

            if(!vis[i]){
                list.add(nums[i]);
                vis[i]=true;
                //不复制不能在这返回还是得回溯，不然影响i+1
                dfs(nums,vis,list);
                list.remove(list.size()-1);
                vis[i]=false;
            }
        }




    }
}



